
// figure on the distribution  of the duration in f2f relationships 

use  base_4decile$firstyear$lastyear, clear
g bin=1 
replace bin=2 if length_bps>1 & length_bps<4
replace bin=3 if length_bps>3 & length_bps<7
replace bin=4 if length_bps>6 & length_bps<13

replace bin=5 if length_bps>12 & length_bps<25
replace bin=6 if length_bps>24 & length_bps<37
replace bin=7 if length_bps>36 & length_bps<49

replace bin=8 if length_bps>48 & length_bps<61
replace bin=9 if length_bps>60 & length_bps<73
replace bin=10 if length_bps>72 

collapse (sum) export (count) nb=export, by(bin)
egen x=sum(export) 
egen n=sum(nb) 
g shx=export/x
g shn=nb/n 

g bin2=bin+0.3
gr tw (bar shn bin, barw(0.3)col( ltkhaki  )) (bar shx bin2, barw(0.3) col(bluishgray )) , ///
 xlabel(1 "1m" 2 "2-3m" 3.3 "4-6m"  4.3 "7-12m"  5.3 "2y"  6.3 "3y" 7 "4y" 8 "5y" 9 "6y" 10 "7y+" )  ///
 ylabel(,angle(0)) legend(label(1 "count") label(2 "value") rows(2) ring(0) pos(3) region(lcolor(white))) ///
 ytitle("share of transactions") 
 graph export $outputpath/figure_online_5.pdf, replace